package com.wellink.viewswitchdemo;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

public class TextSwitcherActivity extends AppCompatActivity {

    TextSwitcher switcher;
    String[] contents = { "你好", "HelloWorld", "Good!!!", "TextSwitcher", "你会了吗？"};
    int index = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.textswitcher_layout);

        switcher = findViewById(R.id.textswitcher);
        switcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView view = new TextView(TextSwitcherActivity.this);
                view.setTextSize(50);
                view.setTextColor(Color.GREEN);
                return view;
            }
        });

        switcher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switcher.setText(contents[index++ % contents.length]);
            }
        });

        switcher.setText(contents[0]);
    }

}
